package com.example.demo.web;

import com.example.demo.dao.UserMapper;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * ClassName : com.example.demo.web.UserCon
 * Desc : TODO
 *
 * @author : LINPQ
 * @date : 2022/6/11 19:18
 */
@RequestMapping("user")
@Controller
public class UserController {

    @Autowired
    UserMapper userMapper;

    @RequestMapping("index")
    public String index(){
        return "";
    }


    @RequestMapping("list")
    @ResponseBody
    public List<User> list(){
        List<User> list = userMapper.list();
        return list;
    }


    @RequestMapping("save")
    @ResponseBody
    public String save(){
        User user = new User();
        user.setId(3);
        user.setName("王五");
        user.setAge(23);
        userMapper.save(user);
        return "保存成功";
    }


    @RequestMapping("update")
    @ResponseBody
    public String update(){
        User user = new User();
        user.setId(3);
        user.setName("王五66666");
        user.setAge(23);
        userMapper.update(user);
        return "修改成功111U31";
    }


    @RequestMapping("delete")
    @ResponseBody
    public String delete(){
        userMapper.delete("3");
        return "删除成功";
    }
}
